# 阶段1: 构建前端应用
FROM node:20-alpine AS builder

# 设置工作目录
WORKDIR /app

# 复制依赖文件
COPY package*.json ./

# 设置npm镜像源为淘宝镜像
RUN npm config set registry https://registry.npmmirror.com

# 安装依赖 - 添加参数优化安装速度
RUN npm install --prefer-offline --no-audit

# 复制项目代码
COPY . .

# 构建项目
RUN npx vite build

# 阶段2: 使用Nginx提供静态文件
FROM nginx:alpine

# 复制Nginx配置文件(如果需要自定义配置)
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 复制构建产物到Nginx的html目录
COPY --from=builder /app/dist /usr/share/nginx/html

# 暴露80端口
EXPOSE 80

# 启动Nginx
CMD ["nginx", "-g", "daemon off;"]